package com.kjc.demo.rcservice.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kjc.demo.rcservice.bean.FileStoreAreaBean;
import com.kjc.demo.rcservice.repository.FileStoreAreaMapper;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.sdhs.paas.sdk.base.common.entity.PaginationEntity;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;

/**
* 描述：FileStoreAreaService 服务接口
* @author kangjichang
* @date 2018-12-03
*/

@EnablePaasMybatis
@MapperScan("com.kjc.demo.rcservice.repository")
@Service
public class FileStoreAreaService extends BaseDao<FileStoreAreaBean, FileStoreAreaMapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return FileStoreAreaMapper.class.getName();
		}
		
		@Autowired
		private FileStoreAreaMapper fileStoreAreaMapper;
		
		public PaginationEntity<FileStoreAreaBean> getPageFileStoreAreaList(BasePage pageRequest, FileStoreAreaBean fileStoreAreaBean) {
			Page<FileStoreAreaBean> pageTotal = PageHelper.startPage(pageRequest.getPage(), pageRequest.getPageSize(),true);
			List<FileStoreAreaBean> list = fileStoreAreaMapper.getList(fileStoreAreaBean);
			PaginationEntity<FileStoreAreaBean> paginationEntity = new PaginationEntity<FileStoreAreaBean>(list,
	                (int) pageTotal.getTotal());
			return paginationEntity;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean saveFileStoreArea(FileStoreAreaBean fileStoreAreaBean) {
			try {
				//ucAppBean.setCtime(System.currentTimeMillis());
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = fileStoreAreaMapper.insertFileStoreArea(fileStoreAreaBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean updateFileStoreArea(FileStoreAreaBean fileStoreAreaBean) {
			try {
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = fileStoreAreaMapper.updateFileStoreArea(fileStoreAreaBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public FileStoreAreaBean getFileStoreAreaDetail(String id) {
			return fileStoreAreaMapper.getFileStoreAreaDetail(id);
		}
		
		public boolean deleteFileStoreArea(FileStoreAreaBean fileStoreAreaBean){
			return fileStoreAreaMapper.deleteFileStoreArea(fileStoreAreaBean)>0;
		}
      
}